const mongoose = require("mongoose")
var crypto = require('crypto');

var MerchantSchema = new mongoose.Schema({
    mPersonName: String,
    mTel: String,
    mIdCard: String,
    mCardPath: String,
    mLocation: String,
    mBrand: String,
    mLogoPath: String,
    hash: String,
    salt: String,
    mStark: Number,
})

MerchantSchema.methods.setPassword = function (password) {
    this.salt = crypto.randomBytes(16).toString('hex');
    this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
};

MerchantSchema.methods.validPassword = function (password) {
    var hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
    return this.hash === hash;
};

mongoose.model("merchant", MerchantSchema);